package com.ldw.mulptiThread;

public class DeadLockDemo {
    public static Object lockA = new Object();
    public static Object lockB = new Object();

    public static void main(String[] args) {
        Thread threadA = new ThreadA();
        Thread threadB = new ThreadB();
        threadA.start();
        threadB.start();
    }

     static class ThreadA extends Thread {
        @Override
        public void run() {
            synchronized (lockA) {
                System.out.println("Thread 1: 持有 A，等待 B...");
                synchronized (lockB) {
                    System.out.println("Thread 1: 持有 A 和 B");
                }
            }
        }
    }
    static class ThreadB extends Thread {
        @Override
        public void run() {
            synchronized (lockB) {
                System.out.println("Thread 1: 持有 B，等待 A...");
                synchronized (lockA) {
                    System.out.println("Thread 1: 持有 A 和 B");
                }
            }
        }
    }
}